claim_throne = {
	
	skill = learning
	desc = claim_throne_desc_general
	hostile = yes
	icon = icon_scheme_claim_throne
	
	allow = {
		is_adult = yes
		is_imprisoned = no
		is_landed = yes
		highest_held_title_tier > tier_barony

		OR = {
			has_perk = meritocracy_perk # Scheme unlocked by the Meritocracy Perk
			AND = {
				is_diarch_of_target = scope:target
				scope:target = {
					NOT = { has_diarchy_parameter = can_be_instantly_dismissed }
				}
			}
			AND = {
				is_powerful_vassal_of = scope:target
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_claim_throne_for_powerful_vassals
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:target
					}
				}
			}
			AND = {
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_claim_throne_for_all
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:target
					}
				}
			}
			AND = {
				exists = title:d_sunni.holder
				is_vassal_of = title:d_sunni.holder
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_claim_throne_for_caliph_vassals
				}
			}
		}
	}
	
	valid = {
		scope:owner = {
			exists = liege
			liege = scope:target
		}
		scope:target = {
			is_landed = yes
			exists = location
		}
		custom_description = {
			text = already_has_strong_claim_on
			object = scope:target
			scope:owner = {
				NOT = { has_strong_claim_on = scope:target.primary_title }
			}
		}
		# Special AI exceptions
		NOT = {
			scope:owner = {
				is_ai = yes
				has_opinion_modifier = {
					target = scope:target
					modifier = repentant_opinion
				}
			}
		}
	}

	valid_agent = {
		age >= 14
	}
	
	agent_join_chance = {
		base = 0
		
		modifier = {
			add = -20
			desc = BASE_RELUCTANCE
		}

		#Is Owner sending a gift in the invite interaction?
		modifier = {
			add = 10
			exists = scope:gift
			always = scope:gift
			NOT = {
				OR = {
					scope:target = { is_parent_of = root }
					root = { is_parent_of = scope:target }
				}
			}
			desc = "SCHEME_WITH_GIFT"
		}

		#Default Hostile Scheme modifiers
		hostile_murder_agent_base_join_chance_modifier = yes
	}
	
	base_success_chance = {
		base = 5
		
		compare_modifier = {
			desc = "SCHEME_MY_LEARNING"
			value = scope:owner.learning
			multiplier = 2
		}

		compare_modifier = {
			desc = "SCHEME_MY_INTRIGUE"
			value = scope:owner.intrigue
		}
		
		modifier = {
			desc = "SCHEME_I_AM_COUNCILLOR_OF_TARGET"
			add = 25
			scope:owner = {
				is_councillor_of = scope:target
			}
		}

		modifier = {
			add = -30
			always = scope:exposed
			desc = "SCHEME_IS_EXPOSED"
		}

		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
	}
	
	agent_success_chance = {
		base = 0

		compare_modifier = {
			desc = "SCHEME_AGENT_LEARNING"
			value = learning
			multiplier = 2
		}
		
		modifier = {
			add = 25
			desc = CLAIM_THRONE_SCHEME_AGENT_COUNCILLOR
			is_councillor_of = scope:target
			trigger_if = {
				limit = { exists = scope:target.cp:councillor_court_chaplain }
				NOT = { this = scope:target.cp:councillor_court_chaplain }
			}
		}

		modifier = {
			add = 50
			desc = CLAIM_THRONE_SCHEME_AGENT_COURT_CHAPLAIN
			exists = scope:target.cp:councillor_court_chaplain
			this = scope:target.cp:councillor_court_chaplain
		}

		modifier = {
			add = 10
			DESC = CLAIM_THRONE_SCHEME_AGENT_VASSAL
			is_vassal_of = scope:target
			NOT = { is_councillor_of = scope:target }
		}
	}
	
	agent_leave_threshold = -10
		
	cooldown = { years = 2 }
	is_secret = yes
	base_secrecy = 10

	on_ready = {
		scheme_target.primary_title = { save_scope_as = target_title }
		scheme_owner = {
			if = {
				limit = {
					has_character_flag = is_executing_claim_throne
				}
				trigger_event = {
					on_action = claim_throne_setup
					days = 1
				}
			}
			else = {
				trigger_event = {
					on_action = claim_throne_setup
				}
			}
		}
	}

	on_monthly = {
		hostile_scheme_discovery_chance_effect = yes
		if = {
			limit = {
				NOT = { exists = scope:discovery_event_happening }
			}			
			scheme_owner = {
				trigger_event = {
					on_action = claim_throne_ongoing
					days = { 1 30 }
				}
			}
		}
	}

	
	on_invalidated = {
		if = {
			limit = { exists = scheme_target.primary_title }
			scheme_target.primary_title = { save_scope_as = target_title }
		}
		scope:owner = {
			trigger_event = { id = claim_throne_outcome.9999 days = 1 }
		}
		if = {
			limit = {
				scope:target = { 
					NOT = { in_diplomatic_range = scope:owner } 
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = fabricate_hook_failed_reset_message
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_in_diplomatic_range
					}
				}
			}
		}
	}
	
	
	power_per_skill_point = 3
	power_per_agent_skill_point = 1
	spymaster_power_per_skill_point = 0 # Needed to stop the Spymaster from affecting the scheme
	resistance_per_skill_point = 2
	spymaster_resistance_per_skill_point = 0 # Needed to stop the Spymaster from affecting the scheme
	
	minimum_progress_chance = 20
	maximum_progress_chance = 80
	minimum_success = 5
	maximum_secrecy = 95
	maximum_success = 90
	
	success_desc = "CLAIM_THRONE_SUCCESS_DESC"
	discovery_desc = "CLAIM_THRONE_DISCOVERY_DESC"
}
